package com.chocho.consumeserver.service;

import com.chocho.consumeserver.client.JavaCompileClient;
import com.chocho.consumeserver.vo.Code;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.remoting.RemoteAccessException;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * Created by chocho on 2022/3/12.
 */
@Service
public class GetwayService {
    @Autowired
    private JavaCompileClient javaCompileServiceClient;

    private Logger logger = LoggerFactory.getLogger(GetwayService.class);

    //调用java-compile-server服务接口
    public void javaCompile(Code code){
        Map<String, Object> map = javaCompileServiceClient.compileJava(code);

        try {
            if (map == null) {
                throw new RemoteAccessException("远程调用编译模块失败!");
            }
        }catch (Exception e) {
            logger.error("RemoteAccessException", e);
        }
    }

    //输入样例时的编译测试
    public Map<String, Object> inputQuestionCompile(Code code){
        Map<String, Object> returnMap = javaCompileServiceClient.compileJava(code);
        return returnMap;
    }
}
